﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangePwd : System.Web.UI.Page, IAccess
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentAccount.CheckSessionTimeOut(this);
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {


            var newpwd = txtNewPwd.Text.Trim();

            if (newpwd != txtNewPwdConfirm.Text.Trim())
            {
                HZ.Web.MessageBox.Show("新密码两次输入不匹配");
                return;
            }

            int i = BLL_Factory.IBLL_Common.ChangePassword(CurrentAccount.Account.AccountId.Value, txtOriginPwd.Text.Trim(), newpwd);

            if (i == 2)
            {
                HZ.Common.log4netManager.LogInfo(Request.Url.ToString(), string.Format("密码修改失败：用户名{0}，原因：原密码不正确.", CurrentAccount.Account.AccountName), null);
                HZ.Web.MessageBox.Show("原密码不正确");
                return;
            }
            if (i != 1)
            {
                HZ.Web.MessageBox.Show("修改失败");
                HZ.Common.log4netManager.LogInfo(Request.Url.ToString(), string.Format("密码修改失败：用户名{0}.", CurrentAccount.Account.AccountName), null);
                return;
            }
            else
            {
                HZ.Web.MessageBox.Show("密码修改成功！");
                HZ.Common.log4netManager.LogInfo(Request.Url.ToString(), string.Format("密码修改成功：用户名{0}.", CurrentAccount.Account.AccountName), null);
                HZ.Web.WebUtil.ClosePage();
            }

        }

    }
    #region IAccess Members

    IList<EnumAccess> IAccess.AccessList
    {
        get
        {
            var list = new List<EnumAccess>();
            list.Add(EnumAccess.Company);
            list.Add(EnumAccess.Manage);
            return list;
        }

    }

    #endregion
}
